@extends('backstage.layout.master')
@section('title', '品牌名限制词列表')
@section('content')
    <link rel="stylesheet" href="assets/css/jquery-ui-1.10.3.custom.min.css"/>
    <link rel="stylesheet" href="assets/css/chosen.css"/>
    <link rel="stylesheet" href="assets/css/datepicker.css"/>
    <link rel="stylesheet" href="assets/css/bootstrap-timepicker.css"/>
    <link rel="stylesheet" href="assets/css/daterangepicker.css"/>
    <link rel="stylesheet" href="assets/css/colorpicker.css"/>
    <style>
        a {
            cursor: pointer;
        }

        .ace-file-input input[type=file] {
            position: static;
        }

        .file-label {
            width: 250px;
        }
    </style>

    <div class="breadcrumbs" id="breadcrumbs">

        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/authentication/brand-list">品牌认证列表</a>
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">

        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        认证
                        <small>
                            <i class="icon-double-angle-right"></i>
                            品牌名限制词列表
                        </small>
                    </h1>
                </div>
                <div class="state">
                    <button class="btn btn-success addKeyword">添加</button>

                    <button class="btn  downloadExcel">下载Excel</button>
                </div>

                <div class="table-responsive">

                    <table id="sample-table-2" class="table table-striped table-bordered table-hover">

                        <thead>
                        <tr>
                            {{--<th class="center">ID</th>--}}
                            <th class="center">限制名</th>
                            <th class="center">创建时间</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($lists as $list)
                            <tr>
                                {{--<td class="center">{{ $list->id }}</td>--}}
                                <td class="center">{{$list->keyword}}</td>
                                <td class="center">
                                    {{ date('Y-m-d H:i:s',$list->created_at) }}
                                </td>
                                <td class="center">
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="edit" onclick="editByid('{{$list->id}}')">修改</a>
                                        <a class="delete" onclick="deleteByid('{{$list->id}}')">删除</a>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <div class="row">
                        <div class="modal-footer no-margin-top">
                            <div class="dataTables_paginate paging_bootstrap">
                                <?php echo $lists->render(); ?>
                            </div>
                        </div>
                    </div>
                </div>
                    <form class="form-horizontal" role="form" action="/backstage/authentication/load-excel"
                          method="post" enctype="multipart/form-data">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">


                        <div class="profile-info-row" style="margin-top: 3%">
                            <p>可导入Excel更新</p>
                            <input type="file" id="loadExcel"
                                   name="ExcelFile" placeholder="EXCEL"
                                   required="required">
                            <button class="btn  loadExcel" type="submit">确定导入</button>
                        </div>

                </form>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')

    <script src="/front/hAdmin/js/plugins/layer/layer.js"></script>
    <script type="text/javascript">
        var _token = '{{csrf_token()}}';
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('#loadExcel').ace_file_input({
                no_file: '选择要导入的excel',
                btn_choose: '选择',
                btn_change: '重新选择',
                droppable: false,
                onchange: null,
                thumbnail: true
            });
        });
        $(".addKeyword").click(function () {
            layer.prompt({title: '输入要添加限制词', formType: 3}, function (text, index) {
                layer.close(index);
                var keyword = text;
                if (keyword == '') {
                    layer.msg('内容不能为空');
                    return;
                }
                $.ajax({
                    type: "post",
                    url: "/backstage/authentication/add-limit",
                    data: {"keyword": keyword, "_token": _token},
                    success: function (msg) {
                        if (msg.state == "M00000") {
                            layer.msg('添加成功!!');
                            setTimeout("location.reload();", 500);
                        } else if (msg.state == "M00001") {
                            layer.msg('关键词已存在!!');
                        }
                    },
                    error: function () {
                        layer.msg('请重试~');
                    }
                });
            });
        });

        function deleteByid(id) {
            layer.confirm('确认删除？', {
                btn: ['是', '否'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: "/backstage/authentication/delete-limit",
                    data: {"id": id, "_token": _token},
                    success: function (msg) {
                        if (msg.state == "M00000") {
                            layer.msg('删除成功', {icon: 1});
                            setTimeout("location.reload();", 500);
                        }
                    },
                    error: function () {
                        layer.msg('请重试~');
                    }
                });
            }, function () {
            });
        }

        function editByid(id) {
            layer.prompt({title: '输入要修改的限制词', formType: 3}, function (text, index) {
                layer.close(index);
                var keyword = text;
                if (keyword == '') {
                    layer.msg('内容不能为空');
                    return;
                }
                $.ajax({
                    type: "post",
                    url: "/backstage/authentication/edit-limit",
                    data: {"id": id, "keyword": keyword, "_token": _token},
                    success: function (msg) {
                        if (msg.state == "M00000") {
                            layer.msg('修改成功!!');
                            setTimeout("location.reload();", 1000);
                        } else if (msg.state == "M00001") {
                            layer.msg('关键词已存在!!');
                        }
                    },
                    error: function () {
                        layer.msg('请重试~');
                    }
                });
            });
        }

        $(".downloadExcel").click(function () {
            $.ajax({
                url: '/backstage/authentication/download-excel',
                type: 'post',
                data: {},
                datatype: 'json',
                success: function (re) {
                    if (re.state == 'M00000') {
                        window.location.href = re.result.url;
                        return;
                    } else {
                        swal('系统繁忙', '请稍后重试', 'warning');
                    }
                },
                error: function () {
                    swal('系统繁忙', '请稍后重试', 'warning');
                }
            });
        });


    </script>
@stop